# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import json
import time

class HouseSpiderPipeline:
    def process_item(self, item, spider):
        return item

class LianjiaHouseMainInfoPipeline:
    def process_item(self, item, spider):
        json_str = json.dumps(item.__dict__['_values'], ensure_ascii=False)
        now = time.strftime('%Y-%m-%d', time.localtime())
        with open('../data/' + now + '-' + item['lp_type'], 'a', encoding='utf-8') as f:
            f.write(json_str + "\n")